<?php
class sw_person_address_model extends MY_Model {
	var $model = 'sw_person_address';
	
	/*function GetJSON()
	{
		$ls_sql	= "	SELECT	A.*, B.GENDER_NAME
					FROM	SW_PERSON_ADDRESS A 
							LEFT JOIN SW_GENDER B ON A.GENDER_ID = B.GENDER_ID 
					WHERE	(UPPER(NVL(A.PERSON_ID,'')) LIKE '%".strtoupper(post('keyword'))."%' 
							OR UPPER(NVL(B.GENDER_NAME,'')) LIKE '%".strtoupper(post('keyword'))."%' 
							OR UPPER(NVL(A.FULL_NAME,'')) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(A.MOTHER_NAME,'')) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(A.IDENTITY_NUMBER,'')) LIKE '%".strtoupper(post('keyword'))."%') 
					ORDER BY ".(post('sort')=='' ? 'A.PERSON_ID' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetDetail($param=array())
	{
		
		$ls_sql	= "	SELECT	A.*
					FROM	SW_PERSON_ADDRESS A
					ORDER BY PERSON_ID";;
		$result = $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return NULL;
		}
	}*/
	
	function Add($arr_data){
		$this->db->insert('SW_PERSON_ADDRESS', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('SW_PERSON_ADDRESS', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_personid, $as_addrtype){
		$result = $this->db->get_where('SW_PERSON_ADDRESS', array('PERSON_ID' => $as_personid, 'ADDRESS_TYPE_CODE' => $as_addrtype));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_personid, $as_addrtype)
	{
		$result = $this->db->get_where('SW_PERSON_ADDRESS', array('PERSON_ID' => $as_personid, 'ADDRESS_TYPE_CODE' => $as_addrtype));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM SIS_ANGGOTA WHERE PERSON_ID = '".$arr_rule['PERSON_ID']."'"))>0)
			{
				return $this->error_delete.' [id: '.$arr_rule['PERSON_ID']."]<br />";
			}else{
				$this->db->delete('SW_PERSON_ADDRESS', array('PERSON_ID' => $arr_rule['PERSON_ID']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>